<?php
$access_level = 0;
$page_title = 'eTAT: Registration';
require_once 'controller.php';
if($params->k == '') {
	$_SESSION['m'] = 7;
	redirect('index.php');
} else {
	$email = base64_decode($params->k);
	$query = mysql_query("SELECT * FROM `instructor` WHERE `email` = '$email' AND `permission` = '1'") or die(mysql_error());
	$instructor = mysql_fetch_object($query);
}
if(isset($_POST['register_submit'])) {
	$password = makePassword($_POST['password']);
	$query = mysql_query("UPDATE `instructor` SET `full_name` = '{$_POST['full_name']}', `password` = '$password', `permission` = '2' WHERE `id` = '{$_POST['id']}';") 	or die(mysql_error());
	redirect('index.php');
}
require_once 'header.php';
?>
<div id="main">
	<h1>Welcome to eTAT!</h1>
	<p>Hi <b><?php print $instructor->email ?></b>,</p>
	<p>Let's get started by creating an account below:</p><br>
	<?php
		$form = new Form('register_form','post');
		$form->textInput('id','id',array('value'=>$instructor->id,'class'=>'invisible'));
		$form->textInput('full_name','Full Name');
		$form->textInput('email','Gmail Address',array('value'=>$instructor->email,'readonly'=>'true'));
		$form->textInput('password','Password',array('type'=>'password'));
		$form->button('register_submit','Create Account',array('type'=>'submit'));
		print $form->build();
	?>
</div>
<?php require_once 'footer.php'; ?>